Use case: Read and write DMA operations

Sequence diagram

Read and write DMA operations

@startuml

== Prerequisite: Initialization and configuration ==

== Process ==

"User Application" -> "HAL SRAM Driver" : HAL_SRAM_Write_DMA()
note right: **Write DMA operation**
"HAL SRAM Driver" --> "User Application": hal status : HAL_OK or HAL_ERROR
note right: **Return**

"User Application" -> "HAL SRAM Driver" : HAL_SRAM_Read_DMA()
note right: **Read DMA operation**
"HAL SRAM Driver" --> "User Application" : hal status : HAL_OK or HAL_ERROR
note right: **Return**

@enduml

Code snippet

HAL1

HAL2

/* Write data to the SRAM memory -------------------- */
HAL_SRAM_Write_DMA(&hsram,
                   (uint32_t *)(target_address),
                   data_to_write,
                   BufferSize
                 );

/* Read data from the SRAM memory */
HAL_SRAM_Read_DMA(&hsram,
                  (uint32_t *)(target_address),
                  data_read,
                  BufferSize
                );
/* Write data to memory */
HAL_DMA_StartDirectXfer_IT(&dma_handle,
                           data_to_write,
                           (uint32_t *)(target_address),
                           BufferSize
                          );

/* Read data from memory */
HAL_DMA_StartDirectXfer_IT(&dma_handle,
                           (uint32_t *)(target_address),
                           data_read,
                           BufferSize
                          );

Key changes

  1. In HAL2, SRAM read/write is done through memory mapping; DMA transfers use direct DMA APIs.

  2. HAL1 uses HAL_SRAM_Read_DMA()/HAL_SRAM_Write_DMA() while HAL2 uses HAL_DMA_StartDirectXfer_IT().